package com.ruoyi.project.system.cs.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.cs.domain.Cs;
import com.ruoyi.project.system.cs.service.ICsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * aaaController
 * 
 * @author ruoyi
 * @date 2020-09-10
 */
@Controller
@RequestMapping("/system/cs")
public class CsController extends BaseController
{
    private String prefix = "system/cs";

    @Autowired
    private ICsService csService;

    @RequiresPermissions("system:cs:view")
    @GetMapping()
    public String cs()
    {
        return prefix + "/cs";
    }

    /**
     * 查询aaa列表
     */
    @RequiresPermissions("system:cs:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Cs cs)
    {
        startPage();
        List<Cs> list = csService.selectCsList(cs);
        return getDataTable(list);
    }

    /**
     * 导出aaa列表
     */
    @RequiresPermissions("system:cs:export")
    @Log(title = "aaa", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Cs cs)
    {
        List<Cs> list = csService.selectCsList(cs);
        ExcelUtil<Cs> util = new ExcelUtil<Cs>(Cs.class);
        return util.exportExcel(list, "cs");
    }

    /**
     * 新增aaa
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存aaa
     */
    @RequiresPermissions("system:cs:add")
    @Log(title = "aaa", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Cs cs)
    {
        return toAjax(csService.insertCs(cs));
    }

    /**
     * 修改aaa
     */
    @GetMapping("/edit/{csId}")
    public String edit(@PathVariable("csId") Long csId, ModelMap mmap)
    {
        Cs cs = csService.selectCsById(csId);
        mmap.put("cs", cs);
        return prefix + "/edit";
    }

    /**
     * 修改保存aaa
     */
    @RequiresPermissions("system:cs:edit")
    @Log(title = "aaa", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Cs cs)
    {
        return toAjax(csService.updateCs(cs));
    }

    /**
     * 删除aaa
     */
    @RequiresPermissions("system:cs:remove")
    @Log(title = "aaa", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(csService.deleteCsByIds(ids));
    }
}
